//package com.alex.springbootdemo.task;
//
//import org.quartz.Trigger;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
//import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
//import org.springframework.stereotype.Component;
//
//import java.text.ParseException;
//
///**
// * 使用quartz框架做定时任务
// * 需要一个任务要在此类中定义一组：job、jobDetail、trigger,并最后将定义的trigger加入到customCronTrigger中
// * 配置麻烦复杂，当定时任务过多时，本类中会定义很多组，不推荐
// */
//@Configuration
//public class QuartzJobDemoConfig {
//
//
//    @Component("myFirstJob")
//    public class MyFirstJob {
//        public void run() {
//            System.out.println("quartz job test run ....");
//        }
//    }
//
//    @Bean(name = "firstJobDetail")
//    public MethodInvokingJobDetailFactoryBean firstJobDetail() {
//        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
//        //设置执行任务的bean
//        jobDetail.setTargetBeanName("myFirstJob");
//        //设置具体执行的方法
//        jobDetail.setTargetMethod("run");
//        //true 任务并发执行
//        //false 下一个任务必须等待上一任务完成
//        jobDetail.setConcurrent(false);
//        return jobDetail;
//    }
//
//    @Bean(name = "firstTrigger")
//    public Trigger firstTrigger(@Qualifier("firstJobDetail") MethodInvokingJobDetailFactoryBean firstJobDetail) throws ParseException {
//        CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
//        cronTriggerFactoryBean.setJobDetail(firstJobDetail.getObject());
//        String cron = "0/5 * * * * ?";
//        cronTriggerFactoryBean.setCronExpression(cron);
//        cronTriggerFactoryBean.setName("firstTrigger");
//        cronTriggerFactoryBean.afterPropertiesSet();
//        return cronTriggerFactoryBean.getObject();
//
//    }
//
//    @Bean(name = "customCronTrigger")
//    public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("firstTrigger") Trigger firstTrigger) {
//        SchedulerFactoryBean bean = new SchedulerFactoryBean();
//        bean.setStartupDelay(1);
//        bean.setTriggers(firstTrigger);
//        return bean;
//    }
//
//}
